﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SQLiteHelp;

namespace TenyGlobalSite.admin
{
    public partial class news_category_add_edit : BasePage
    {
        int cid = 0;
        /// <summary>
        /// 更新模式
        /// </summary>
        protected bool UpdateMode
        {
            get
            {
                if (!string.IsNullOrEmpty(Request.QueryString["id"]))
                {
                    cid = int.Parse(Request.QueryString["id"]);
                    ViewState["cid"] = int.Parse(Request.QueryString["id"]);
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                if (UpdateMode)
                {
                    InitPageContent(cid);
                }
            }
        }

        private void InitPageContent(int cid)
        {
           string name = NewsCategory.GetCategoryNameByID(cid);
           this.txtCategory.Text = name;
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if (!UpdateMode)
            {
                NewsCategory.CreateNewsCategory(this.txtCategory.Text.Trim());
            }
            else
            {
                NewsCategory.UpdateCategory(cid, this.txtCategory.Text.Trim());
            }
            Response.Redirect("news_category.aspx");
        }
    }
}